//
//  AppDelegate.swift
//  SainMicroblog
//
//  Created by chenxinju on 16/5/3.
//  Copyright © 2016年 chenxinju-a2. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    //设置根视图

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
        //设置根视图控制器
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
       
        //系统奔溃提示
        //fatalError("在delegate导致启动奔溃");
        
        //设置根控制器视图
       if WBOauthViewModel.shareInstance.islogin { //已经登陆 跳转欢迎界面
            
            window?.rootViewController = WBWelcomeViewController()
           
        }else { //未登陆 跳转到taber
            window?.rootViewController = WBTabBarController()
        }
    
         //让根视图显示
            window?.makeKeyAndVisible()
        
        //显示tabbar的字体颜色在程序启动统一设置
         setBarColor()
        
        //2.监听通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeViewCotroller:", name:kNotificationChangeViewControler, object: nil)
        
        return true
    
    }
    
    //4.实现一个 通知的方法
    @objc private  func changeViewCotroller(noto:NSNotification) {
    
     // print(noto.object)
        //区分
        if noto.object is WBOauthViewController {
           //进入欢迎控制器
          window?.rootViewController = WBWelcomeViewController()
        }else if noto.object is WBWelcomeViewController {
        window?.rootViewController = WBTabBarController()
        }
    }

    //改变tabBar颜色的方法
    func setBarColor() {
        
        //设置渲染颜色
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        //设置导航栏的item字体颜色
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        
    }
    
    //3.移除通知
    deinit {
     NSNotificationCenter.defaultCenter().removeObserver(self, name: kNotificationChangeViewControler, object: nil)
    
    }
    
    func applicationWillResignActive(application: UIApplication) {
       
    }
//    MARK:- 程序进入后台删除过期的数据
    func applicationDidEnterBackground(application: UIApplication) {
        WBStatusListModel.shareInstance.deleData()
    }

    func applicationWillEnterForeground(application: UIApplication) {
    
    }

    func applicationDidBecomeActive(application: UIApplication) {
   
    }

    func applicationWillTerminate(application: UIApplication) {
       
    }


}

